#include  <string>
#include <iostream>
#include <fstream>
#include "cJSON.h"
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstdlib>
#include <sys/msg.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/errno.h>
#include <cstring>

#include "communicate1.h"

int main() {

    std::ofstream fout_errors, fout_warmings, fout_infos;
    fout_errors.open(R"(data\edge\errors.log)", std::ios_base::out | std::ios_base::app);
    fout_warmings.open(R"(data\edge\warmings.log)", std::ios_base::out | std::ios_base::app);
    fout_infos.open(R"(data\edge\infos.log)", std::ios_base::out | std::ios_base::app);

    //判断文件是否打开成功
    if ((fout_errors.is_open()) && (fout_warmings.is_open()) && (fout_infos.is_open())) {
        //若成功打开文件，向数据存储子系统获取令牌
        //communicate1();
        //发送成功事件

        //创建用于记录本次启动运行日期时间的文件
        std::ofstream fout_lastrun;
        fout_lastrun.open(R"(edge\lastrun.txt)", std::ios_base::out | std::ios_base::app);
        if (fout_lastrun.is_open()) {
            time_t t;
            time(&t);
            fout_lastrun << ctime(&t);
            char *tt=NULL;
            tt=ctime(&t);
            fout_lastrun<<tt;
            fout_lastrun.close();
        } else {
            //若失败，向消息队列发送“失败”事件，失败原因和等级

        }
    }
        fout_errors.close();
        fout_warmings.close();
        fout_infos.close();
        return 0;
}